﻿CREATE TABLE [dbo].[Articole] (
    [IDArticol]            INT             IDENTITY (1, 1) NOT NULL,
    [CodArticol]           VARCHAR (50)    CONSTRAINT [DF_Articole_CodArticol] DEFAULT ('') NOT NULL,
    [Denumire]             VARCHAR (100)   NOT NULL,
    [IDCategorie]          SMALLINT        NOT NULL,
    [CodUnitate]           SMALLINT        NOT NULL,
    [IDUnitateMasura]      SMALLINT        NOT NULL,
    [Cont]                 [dbo].[TipCont] CONSTRAINT [DF_Articole_Cont] DEFAULT ('N/A') NOT NULL,
    [ContCheltuiala]       [dbo].[TipCont] CONSTRAINT [DF_Articole_ContCheltuiala] DEFAULT ('N/A') NOT NULL,
    [Greutate]             FLOAT (53)      CONSTRAINT [DF_Articole_Greutate] DEFAULT ((0)) NOT NULL,
    [CotaTVA]              DECIMAL (5, 2)  CONSTRAINT [DF_Articole_CotaTVA] DEFAULT ((0)) NOT NULL,
    [EsteServiciu]         BIT             CONSTRAINT [DF_Articole_EsteServiciu] DEFAULT ((0)) NOT NULL,
    [ContVenit]            [dbo].[TipCont] NULL,
    [PretVanzare]          DECIMAL (18, 2) CONSTRAINT [DF_Articole_PretVanzare] DEFAULT ((0)) NOT NULL,
    [ArtAl]                VARCHAR (40)    NULL,
    [PretVanzareValuta]    DECIMAL (18, 4) DEFAULT ((0)) NOT NULL,
    [PretVanzareCodValuta] SMALLINT        DEFAULT ((0)) NOT NULL,
    [MateriePrima]         BIT             DEFAULT ((0)) NOT NULL,
    [Lungime]              FLOAT (53)      NULL,
    [Latime]               FLOAT (53)      NULL,
    [Grosime]              FLOAT (53)      NULL,
    [Raft]                 VARCHAR (50)    NULL,
    [CodCPV]               NVARCHAR (12)   NULL,
    CONSTRAINT [PK_Articole] PRIMARY KEY CLUSTERED ([IDArticol] ASC),
    CONSTRAINT [FK_Articole_ArticoleAliniate] FOREIGN KEY ([ArtAl], [CodUnitate]) REFERENCES [dbo].[ArticoleAliniate] ([ArtAl], [CodUnitate]),
    CONSTRAINT [FK_Articole_CategoriiArticole] FOREIGN KEY ([IDCategorie]) REFERENCES [dbo].[TipCategoriiArticole] ([IDCategorie]),
    CONSTRAINT [FK_Articole_Conturi] FOREIGN KEY ([Cont], [CodUnitate]) REFERENCES [dbo].[Conturi] ([Cont], [CodUnitate]),
    CONSTRAINT [FK_Articole_ConturiCheltuiala] FOREIGN KEY ([ContCheltuiala], [CodUnitate]) REFERENCES [dbo].[Conturi] ([Cont], [CodUnitate]),
    CONSTRAINT [FK_Articole_CPV] FOREIGN KEY ([CodCPV]) REFERENCES [dbo].[CPV] ([Cod]),
    CONSTRAINT [FK_Articole_Unitati] FOREIGN KEY ([CodUnitate]) REFERENCES [dbo].[Unitati] ([CodUnitate]),
    CONSTRAINT [FK_Articole_UnitatiMasura] FOREIGN KEY ([IDUnitateMasura]) REFERENCES [dbo].[UnitatiMasura] ([IDUnitateMasura]),
    CONSTRAINT [FK_Articole_Valuta] FOREIGN KEY ([PretVanzareCodValuta]) REFERENCES [dbo].[Valuta] ([CodValuta]),
    CONSTRAINT [IX_CodArticolUnitate] UNIQUE NONCLUSTERED ([CodArticol] ASC, [CodUnitate] ASC)
);

